#ifndef SIPTRANSESSIONBASE_HPP__
#define SIPTRANSESSIONBASE_HPP__

#include "WTSXSipService/SipWTSXServiceItf.hpp"
#include "WTSXSipService/SipSessionBase.hpp"
#include "WTResipDll/SipWTResipDllItf.hpp"
//#include "SipClnTransaction.hpp"
//#include "SipSrvTransaction.hpp"

namespace wtsxsip{


class CSipSessionMgr;

class WTSX_SIPSRV_PUBLIC CSipTranSession:
    public CSipSessionBase,
    public ISipTranSession,
    public wtsip::ISipClnTransactionCallback,
    public wtsip::ISipSrvTransactionListener
{
public:

    CSipTranSession(CSipSessionMgr& mgr, uint32_t id, wtsip::ISipClnTransaction& clntran, wtsip::CapSipMessage request);

    CSipTranSession(CSipSessionMgr& mgr, uint32_t id, wtsip::ISipSrvTransaction& srvtran, wtsip::CapSipMessage request);

    virtual ~CSipTranSession();

    virtual bool messageDress(wtsip::CSipMessage& msg);

    virtual bool cancel();

    virtual bool send();

    virtual bool send(const SMsgBodyBase& body);

    virtual ISipTranSession::ETranSessionState getTranSessionState();

    virtual bool isClient();

    virtual wtsip::CSipMessage* getRequest();

    ////////////////////// ISipTranSession methods //////////////////////

    virtual uint32_t getHandle();

    virtual bool reply(const SHeaders& headers, bool canceled=false);

    virtual bool reply(const SHeaders& headers, const SMsgBodyBase& body, bool canceled=false);

    virtual bool registerHandle(ISipTranSessionHandle* h);

    virtual bool unregisterHandle(ISipTranSessionHandle* h);

    ///////////////////// Transaction handle method ////////////////////

    virtual bool onResponse(wtsip::ISipClnTransaction& clntran, wtsip::CapSipMessage msg);

    virtual bool onDestroy(wtsip::ISipClnTransaction& clntran);

    virtual bool onState(wtsip::ISipClnTransaction& clntran, wtsip::ISipClnTransaction::EClnTranState newState);

    virtual bool onRequest(wtsip::ISipSrvTransaction& srvtran, wtsip::CapSipMessage msg);

    virtual bool onDestroy(wtsip::ISipSrvTransaction& srvtran);

    virtual bool onState(wtsip::ISipSrvTransaction& srvtran, wtsip::ISipSrvTransaction::ESrvTranState newState);

protected:

    virtual bool onDestroy();

    virtual bool handleRequest(const SHeaders& headers, const SMsgBodyBase& body);

    virtual bool handleResponse(const SHeaders& headers, const SMsgBodyBase& body);

    virtual bool handleState(const ETranSessionState newState);

    virtual bool handleDestroy();   

private:

    ETranSessionState m_state;

    wtsip::CapSipMessage m_request;

    wtsip::CapSipMessage m_cancel;

    wtsip::ISipClnTransaction* m_clnTran;

    wtsip::ISipSrvTransaction* m_srvTran;

    std::vector<ISipTranSessionHandle*> m_handleList;

};


}//namespace


#endif


